package cn.com.servletcontext;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "sContext03", value = "/sContext03")
public class sContext03 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        // 获取ServletContext对象，该对象包含了Web应用程序的上下文信息
        ServletContext context = this.getServletContext();
        //获取其他servlet定义的应用范围的数据
        String data = (String) context.getAttribute("data");
        PrintWriter out = response.getWriter();
        out.println(data);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}